package com.muqi.app.qlearn.adapter;

import java.util.ArrayList;

import android.content.ClipData.Item;
import android.content.Context;
import android.opengl.Visibility;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.muqi.app.network.http.GlideImageUtils;
import com.muqi.app.qlearn.modles.PayTypeInfo;
import com.muqi.app.qlearn.modles.TreeInfo;
import com.muqi.app.qlearn.student.R;

import com.muqi.app.user.widget.SelectableRoundedImageView;

public class PayTypeAdapter extends BaseAdapter {
	private ArrayList<ArrayList<PayTypeInfo>> infos;
	private Context content;
	private LayoutInflater inflater;
	private onPayClick payClick;

	public PayTypeAdapter(ArrayList<ArrayList<PayTypeInfo>> infos,
			Context content) {
		super();
		this.infos = infos;
		this.content = content;
		inflater = LayoutInflater.from(content);
	}


	public void setPayClick(onPayClick payClick) {
		this.payClick = payClick;
	}

	@Override
	public int getCount() {
		return infos.size();
	}

	@Override
	public Object getItem(int arg0) {
		return infos.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(final int arg0, View arg1, ViewGroup arg2) {
		ViewHolder holder = null;
		if (arg1 == null) {
			arg1 = inflater.inflate(R.layout.item_pay_type, null);
			holder = new ViewHolder();
			holder.itemType = (Button) arg1.findViewById(R.id.bt1);

			holder.itemDes = (TextView) arg1.findViewById(R.id.tv_des);
			holder.itemContainer = (LinearLayout) arg1
					.findViewById(R.id.ll_type_container);

			arg1.setTag(holder);
		} else {
			holder = (ViewHolder) arg1.getTag();
		}
		holder.itemContainer.removeAllViews();
		ArrayList<PayTypeInfo> list = infos.get(arg0);
		if (list != null && list.size() > 0) {
			if (arg0 == 0) {
				holder.itemType.setText("基本型");
				holder.itemDes.setVisibility(View.GONE);
			} else {
				holder.itemType.setText("送花型");
				holder.itemDes.setVisibility(View.VISIBLE);
			}
			for (int i = 0; i <list.size(); i++) {
				final PayTypeInfo temp=list.get(i);
				if(temp!=null){
					View view=inflater.inflate(R.layout.view_paytype, null);
					((TextView)view.findViewById(R.id.tv_year)).setText((i+1)+":"+temp.description);
				      view.findViewById(R.id.bt_member_year_pay).setOnClickListener(new OnClickListener() {
						
						@Override
						public void onClick(View arg0) {
							payClick.onClick(temp);							
						}
					});
				      holder.itemContainer.addView(view);
				
				}
				
			}
			

		}

		return arg1;
	}

	

	private class ViewHolder {
		Button itemType;
		TextView itemDes;
		LinearLayout itemContainer;
		/*TextView itemMonth;
		TextView itemYear;
		Button itemPayMonth;
		Button itemPayYear;*/
		
		
	}
  public interface onPayClick{
		void onClick(PayTypeInfo onfo);
  }
	

}
